﻿using System;

namespace TowerofHanoi
{
    class Program
    {/// <summary>
     /// 汉诺塔问题
     /// </summary>
     /// <param name="args"></param>
        static int i = 0;
        static void Main(string[] args)
        {
            Console.WriteLine("Please enter the total number of Hanoi plates ：");
            int n = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Progress of movement for{0} Hanoi plates", n);
            Console.WriteLine("步数：" + MovePlate(n, 'A', 'B', 'C'));
            Console.WriteLine();
        }
        //n，x,y,z分别代表要处理的汉诺盘数，n号汉诺盘原来所在的柱子，经由柱子，最终柱子。
        public static int MovePlate(int n, char a, char b, char c)
        {
            if (n == 1)
            {
                Console.WriteLine("Move plate {0} from {1} to {2}", a, a, c);//将1号汉诺盘从a柱移到c柱
            }
            else
            {
                i = MovePlate(n - 1, a, c, b);//将剩余n-1个汉诺盘从a柱经由c柱移到b柱
                Console.WriteLine("Move plate {0} from {1} to {2}", n, a, b, c);//将剩余n-1个汉诺盘从b柱经由a柱移到c柱
                i = MovePlate(n - 1, b, a, c);
            }
            return ++i;
        }

    }
}
